

def jwt_response_payload_handler(token,user=None, request=None):
    print(token)
    print(user)
    print(request)
    return {
        'token':token,
        'username':user.username,
        'id':user.id,
    }

def get_user_by_account(account):
    try:
        if re.match(r'^1[3-9]\d{9}$', account):
            user = models.User.objects.get(mobile=account)
        else:
            user = models.User.objects.get(username=account)
    except models.User.DoesNotExist:
        return None
    else:
        return user




import re
from django.contrib.auth.backends import ModelBackend
from . import models
class UsernameMobileAuthBackend(ModelBackend):

    def authenticate(self, request, username=None, password=None, **kwargs):
        user = get_user_by_account(username)
        if user is not None and user.check_password(password):

            return user








